if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[sp_HangTon_UpdateSoLuongTonKhoOfNhapHangNCCByMaChiNhanh_MaHang]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
drop procedure [dbo].[sp_HangTon_UpdateSoLuongTonKhoOfNhapHangNCCByMaChiNhanh_MaHang]
go

create proc [sp_HangTon_UpdateSoLuongTonKhoOfNhapHangNCCByMaChiNhanh_MaHang]
	@Ma_chi_nhanh		int,
	@Ma_hang_hoa		int,
	@So_luong			float
AS
BEGIN
	DECLARE @Ma_kho_hang int
	DECLARE @So_luong_hien_tai float
	SELECT @Ma_kho_hang = ID FROM KhoHang WHERE Ma_chi_nhanh = @Ma_chi_nhanh
	SELECT @So_luong_hien_tai = So_luong FROM HangTon WHERE Ma_kho_hang = @Ma_kho_hang AND Ma_hang = @Ma_hang_hoa
	UPDATE HangTon
	SET 
		So_luong = (@So_luong_hien_tai + @So_luong)
	WHERE Ma_kho_hang = @Ma_kho_hang AND Ma_hang = @Ma_hang_hoa
END
--Hang hoa tra ve NCC nhung voi du an hien tai
--se luong tru di o chinh nhanh nhung se phai
--cong vao kho cua chinh nhanh chinh
--lam sao biet cai nao la kho chi nhanh chinh =.=